<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Quick_Sort</title>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script>

        function sortMethod() {
            var beforeStr=$("#beforeSort").val();
            var beforeArr=beforeStr.split(",");
            var beforeArrInt=new Array();
            var fileInStr="";
            for (var i=0;i<beforeArr.length;i++){
                beforeArrInt.push(parseInt( beforeArr[i],10));
            }
            var end=beforeArrInt.length-1;
            var afterSort=quickSort(beforeArrInt,0,end);

            $("#afterSort").val(afterSort.join(","));
        }
        function quickSort(numbers,start,end) {
            if (start < end) {
                var base = numbers[start]; // 选定的基准值（第一个数值作为基准值）
                var temp; // 记录临时中间值
                var i = start, j = end;
                do {
                    while ((numbers[i] < base) && (i < end))
                        i++;
                    while ((numbers[j] > base) && (j > start))
                        j--;
                    if (i <= j) {
                        temp = numbers[i];
                        numbers[i] = numbers[j];
                        numbers[j] = temp;
                        i++;
                        j--;
                    }
                } while (i <= j);
                if (start < j)
                    quickSort(numbers, start, j);
                if (end > i)
                    quickSort(numbers, i, end);
            }
            return numbers;
        }
    </script>
</head>
<body>
    排序前：<input id="beforeSort" type="text" onblur=""/>
    <input type="button" value="排序" onclick="sortMethod()">
    排序后：<input id="afterSort" type="text" >
</body>
</html>